// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

// 云函数入口函数
exports.main = async (event, context) => {
  const db = cloud.database();
  const queueCollection = db.collection('notify');
  let queueResult = await queueCollection.limit(1).get();
  try {
    const result = await cloud.openapi.subscribeMessage.send({
      touser: queueResult.data._openid,
      page: 'pages/report/report',
      lang: 'zh_CN',
      data: {
        phrase4: {
          value: '339208499'
        },
        thing6: {
          value: '2015年01月05日'
        },
        thing8: {
          value: 'TIT创意园'
        }
      },
      templateId: 'D6wOUVoU1VXScIxra0DxKiVXHe99VDOsLYLlrZtLPQ4',
    })
  } catch (err) {
    console.log(err)
    return err
  }
}